<template>
  <dt-modal-edit ref='edit' :title='title' :label-width='130' okText='提交审核' :width='600'
    @ok='onOk'>
    <div class="flex">
      <div class="flex-1">
      </div>
      <Button type='text' class="tip" @click="onTip">
        <Icon type="ios-alert" />
        佣金规则说明
      </Button>
    </div>

    <rule-explain ref="explain" />
  </dt-modal-edit>
</template>

<script>
  import editMgr from '../opt/edit.js'
  import ruleMgr from '@/biz/commission/rule.js'
  import ruleExplain from '../components/rule-explain.vue'

  export default {
    components: {
      ruleExplain
    },
    data() {
      return {
        info: {},
        title: '新建佣金规则'
      }
    },
    mounted() {},
    methods: {
      create() {
        this.title = '新建佣金规则'
        this.info = {
          baseAgentType: '1',
          baseAgentCost: null,
          commissionWay: '1',
          contractPer: null,
          depositPer: null,
          validWay: '2',
          refPrice: '1',
          ruleName: null,
          housesId: null,
          companyId: null,
          startDate: null,
          endDate: null,
          accessoryBOList: [],
          productIds: null,
          isDeductDeposit: true
        }
        this.show()
      },
      edit(info) {
        this.title = '重新发起佣金规则'
        this.info = info
        this.show()
      },
      copy(info) {
        this.title = '复制佣金规则'
        this.info = info
        this.show()
      },
      show() {
        this.$refs.edit.show(editMgr.options(this), this.info)
      },
      hide() {
        this.$refs.edit.hide()
      },
      update() {
        this.$refs.edit.update(editMgr.options(this, true))
      },
      onOk(data) {
        console.log(this.info,'aaaaaaaaaaaaaaaaa');
        ruleMgr.save(this.info).then(res => {
          this.$emit('success')
          this.hide()
        })
      },
      onTip() {
        this.$refs.explain.show()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .tip {
    color: #0066CC;
  }
  
  ::v-deep .ivu-modal-body {
    max-height: calc(100vh - 250px);
    overflow-y: auto;
  }
</style>